package com.qr.controller;


import com.qr.factory.CommonFactory;
import com.qr.service.IAccountService;
import com.qr.service.impl.IAccountServiceImpl;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AccountController {
    public static void main(String[] args) {

        //在resource目录下的mapper文件夹中
        ClassPathXmlApplicationContext bean = new ClassPathXmlApplicationContext("bean.xml");

        //默认就是调用无参构造验证，IAccountServiceImpl的构造会输出    对象创建了   看控制台是否有对应输出

        IAccountService accountService = (IAccountService) bean.getBean("accountService");

        accountService.saveAccount();


        /**
         * 普通工厂创建
         *      工厂拿到的和通过找工厂拿到的就是同一个
         */
        System.out.println("普通工厂创建");
        ClassPathXmlApplicationContext commonBean = new ClassPathXmlApplicationContext("Commonbean.xml");
        IAccountService accountService1 = (IAccountService) commonBean.getBean("accountService");
        CommonFactory commonFactory = (CommonFactory) commonBean.getBean("commonFactory");
        IAccountServiceImpl bean1 = commonFactory.getBean();
        System.out.println(bean1);
        bean1.saveAccount();
        System.out.println("===========================");
        accountService1.saveAccount();


        /**
         * 静态工厂创建
         */
        System.out.println("===========================");
        System.out.println("静态工厂创建");
        ClassPathXmlApplicationContext staticBean = new ClassPathXmlApplicationContext("Staticbean.xml");
        IAccountService accountService2 = (IAccountService) staticBean.getBean("accountService");
        accountService2.saveAccount();

    }
}
